<template>
	<div class="icons">
		<swiper :options="swiperOption">
			<!--循环pages方法,这是一个计算属性-->
			<swiper-slide v-for="(page,index) of pages" :key="index">
				<div class="icon" v-for="item of page" :key="item.id">
					<div class="icon-img">
						<img class="icon-img-content" :src="item.imgUrl"/>
					</div>
					<p class="icon-desc">{{item.desc}}</p>
				</div>
			</swiper-slide>
		</swiper>
	</div>
</template>

<script>
	export default {
		name:"HomeIcons",
		props:{
			list:Array
		},
		data (){
			return {
				swiperOption: {
					pagination:'.swiper-pagination',
					loop:false,
					autoplay:false
				}
			}
		},
//		通过计算属性,确定需要多少页轮播来放置Icons
		computed:{
//			用方法pages,通过接收进来的参数,用索引index来计算需要多少页
			pages(){
				const pages = [];
				this.list.forEach((item, index) =>{
					const page = Math.floor(index / 8);
					if(!pages[page]){
						pages[page] = []
					}
					pages[page].push(item)
				})
				return pages
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
	.icons >>> .swiper-container
		height:0
		padding-bottom:40%
	.icon
		overflow:hidden
		position:relative
		width:25%
		float:left
		padding-bottom:20%
		text-align:center
		.icon-img
			position:absolute
			top:0
			left:0
			right:0
			bottom:.4rem
			box-sizing:border-box
			padding:.15rem
			.icon-img-content
				display:block
				margin:0 auto
				height:100%
		.icon-desc
			position:absolute
			color:$darkTextColor
			left:0
			right:0
			bottom:0
			height:.5rem
			line-height:.5rem
			font-size:.24rem
			ellipsis()
</style>